package com.zhzh.sc.demo.juc.thread;

import java.lang.ref.WeakReference;

/**
 * @author: dasouche
 * @date: 2021-03-12 15:50
 **/
public class NormalReference {

    public static void main(String[] args) {
        WeakReference<M> m = new WeakReference<>(new M());
//        M m = new M();
//        m = null;
        System.out.println(m.get());
        System.gc();
        System.out.println(m.get());

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        ThreadLocal<M> tl = new ThreadLocal<>();
        tl.set(new M());
        // ThreadLocal需手动remove
        tl.remove();
    }
}
